<script language="javascript">
	//Grupos de Acesso------------------------------------------------------------------------
			$(document).ready(function(){
			 
				//mascaras padrao
				 $(".cnpj").mask("99.999.999/9999-99");	
			  	 $(".tel").mask("(99)9999-9999");	
				 $(".cep").mask("99.999-999");	

		   }); // fim do document ready
		   
		   
		   
		   
		   
		   //função responsavel por buscar o endereço atraves do cep
		function getHTTPObject() 
		{
			 var xmlhttp;
			 /*@cc_on
			 @if (@_jscript_version >= 5)
			 try {
			 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			 } catch (e) {
			 try {
			 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			 } catch (E) {
			 xmlhttp = false;
			 }
			 }
			 @else
			 xmlhttp = false;
			 @end @*/
		 if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
		  {
			try {
					 xmlhttp = new XMLHttpRequest();
				} catch (e) {
					 xmlhttp = false;
				 }
		  }
			
			return xmlhttp;
		}
		
		var http = getHTTPObject();
		 
		function funcaowebservicecep() 
		{
				 cep = $('#cep').val();
				 cep = cep.replace('.','');
				 cep = cep.replace('-','');
				
			 $('#carregando').html('<p align="center"><img src="images/ajax-loader1.gif" /></p>');
		
			 
			 http.open("GET", 'clientes.php?acao=buscarEndereco&cep='+cep, true);
			 http.onreadystatechange = handleHttpResponse;
			 http.send(null);
		 
			 var arr; //array com os dados retornados
			 function handleHttpResponse() 
			 {
				 if (http.readyState == 4) 
				  {
					 var response = http.responseText;
					 
					 eval("var arr = "+response); //cria objeto com o resultado
					 $("#rua").val(arr.rua);
					 document.getElementById("bairro").value = arr.bairro;
					 document.getElementById("cidade").value = arr.cidade;
					 document.getElementById("uf").value = arr.uf;
					 
					 $('#carregando').html('');
				 }
			}
		}
		
</script>

<div class="grid_16">
  <form name="form" id="form" action="fornecedor.php?acao=salvar" >
    <div class="grid_16">
      <fieldset class="login">
      <legend>Fornecedor</legend>
      <div class="grid_4">
        <label>Nome</label>
        <p>
          <input type="text" name="nome" id="nome" required="required">
      </div>
      
      <div class="grid_4">
        <label>Nome Fantasia</label>
        <p>
          <input type="text" name="nomeFantasia" id="nomeFantasia" required="required">
      </div>
      
      <div class="grid_4">
        <label>Cnpj</label>
        <p>
          <input type="text" name="cnpj" class="cnpj" id="cnpj">
      </div>
      <div class="grid_4">
        <label>Telefone</label>
        <p>
          <input type="text" class="tel" name="telefone" id="telefone">
      </div>
      <div class="grid_4">
        <label>Telefone/Fax</label>
        <p>
          <input type="text" class="tel" name="telefone2" id="telefone2">
      </div>
      
      <div class="grid_4">
        <label>Conta</label>
        <p>
          <input type="text" name="conta" id="conta">
      </div>
      
      <div class="grid_4">
        <label>CEP</label>
        <p>
          <input type="text" class="cep" onBlur="funcaowebservicecep();" name="cep" id="cep">
      </div>
      
      
      <div class="grid_4">
        <label>Rua</label>
        <p>
          <input type="text" name="rua" id="rua">
      </div>
      
      <div class="grid_4">
        <label>Número</label>
        <p>
          <input type="text" name="numero" id="numero">
      </div>
      
      <div class="grid_4">
        <label>Bairro</label>
        <p>
          <input type="text" name="bairro" id="bairro">
      </div>
      
      <div class="grid_4">
        <label>Cidade</label>
        <p>
          <input type="text" name="cidade" id="cidade">
      </div>
      
      <div class="grid_4">
        <label>País</label>
        <p>
          <input type="text" name="pais" id="pais" />
        
      </div>
      


      <p align="center"> <span class="CaptionEsq">
        <input name="codigoFornecedor" type="hidden" id="codigoFornecedor"  size="30" maxlength="10" class="formulario" value="<?php echo $info["codigoFornecedor"]; ?>"  />
        </span> <br>
        <input type="submit" id="salvarFornecedor"  name="salvarFornecedor" value="Salvar"/>
      </p>
      </fieldset>
    </div>
  </form>
</div>
